package com.example.listener;

import com.example.filter.SaTokenContextFilterForServlet;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MyServletContextListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        log.info("------------------------MyServletContextListener-------------------------------------");
        ServletContext servletContext = sce.getServletContext();
        servletContext.addFilter("SaTokenContextFilterForServlet", SaTokenContextFilterForServlet.class)
                      .addMappingForUrlPatterns(null, true, "/*");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        // 清理资源
    }
}